package platformer.model.elements.attributes;

/**
 * The Class TekPoints.
 * 
 * It keeps record of the remaining tek points of the element.
 * This is a generic point counter class. It can be used to create HitPoints, 
 * Mana Points, Energy Points, Cool Points, etc...
 * 
 */
public class TekPoints
{
	
	/** The total tek points. */
	private Long totalTekPoints;
	
	/** The current tek points. */
	private Long currentTekPoints;	
	
	/**
	 * Inits the private members.
	 *
	 * @param totalTekPoints the total tek points
	 */
	private void init( long totalTekPoints ) {		
		this.setTotalTekPoints( totalTekPoints );
		this.setCurrentTekPoints( totalTekPoints );
	}
	
	/**
	 * Instantiates a new tek points with a long.
	 * If totalhitPoints <= 0 then
	 * totalTekpoins = 1
	 * currentTekPoints = 0
	 *
	 * @param totalTekPoints the total tek points
	 */
	public TekPoints( long totalTekPoints ) {
		init(totalTekPoints);
	}
	
	/**
	 * Instantiates a new tek points with a Lng.
	 * If totalhitPoints <= 0 then 
	 * totalTekpoins = 1
	 * currentTekPoints = 0
	 *
	 * @param totalTekPoints the total tek points
	 */
	public TekPoints( Long totalTekPoints ) {
		init( totalTekPoints.longValue() );
	}
	
	/**
	 * Instantiates a new tek points.
	 *
	 * @param tekPoints the tek points
	 */
	public TekPoints( TekPoints tekPoints ) {
		init( tekPoints.totalTekPoints.longValue() );
	}	

	/**
	 * Gets the total tek points.
	 *
	 * @return the total tek points
	 */
	public Long getTotalTekPoints(){
		return totalTekPoints;
	}

	/**
	 * Sets the total tek points.
	 * if tekPoints <= 0 then
	 * totalTekpoins = 1
	 *
	 * @param tekPoints the new total tek points
	 */
	public void setTotalTekPoints( Long tekPoints )
	{		
		if( tekPoints.longValue() > 0 )
			this.totalTekPoints = tekPoints;
		else
			this.totalTekPoints = new Long(1);
		
		if ( this.currentTekPoints > totalTekPoints )
			this.setCurrentTekPoints( new Long( totalTekPoints.longValue() ) );
	}
	
	/**
	 * Sets the total tek points.
	 * if tekPoints <= 0 then
	 * totalTekpoins = 1
	 *
	 * @param tekPoints the new total tek points
	 */
	public void setTotalTekPoints( long tekPoints ){		
		this.setTotalTekPoints( new Long(tekPoints) );
	}
	
	/**
	 * Sets the total tek points.
	 * if tekPoints <= 0 then
	 * totalTekpoins = 1
	 *
	 * @param tekPoints the new total tek points
	 */
	public void setTotalTekPoints( int tekPoints )
	{		
		this.setTotalTekPoints( new Long(tekPoints) );
	}

	/**
	 * Gets the current tek points.
	 *
	 * @return the current tek points
	 */
	public Long getCurrentTekPoints()
	{
		return currentTekPoints;
	}

	/**
	 * Sets the current tek points.
	 * if tekPoints < 0 then
	 * currentTekPoints = 0
	 *
	 * @param tekPoints the new current tek points
	 */
	public void setCurrentTekPoints( Long tekPoints )
	{
		if( tekPoints.longValue()>=0 )
			this.currentTekPoints = tekPoints;
		else
			this.currentTekPoints = new Long(0);
		
		if ( this.currentTekPoints > totalTekPoints )
			this.setCurrentTekPoints( new Long( totalTekPoints.longValue() ) );
	}
	
	/**
	 * Sets the current tek points.
	 * if tekPoints < 0 then
	 * currentTekPoints = 0
	 *
	 * @param tekPoints the new current tek points
	 */
	public void setCurrentTekPoints( long tekPoints )
	{
		this.setCurrentTekPoints( new Long(tekPoints) );
	}
	
	/**
	 * Sets the current tek points.
	 * if tekPoints < 0 then
	 * currentTekPoints = 0
	 *
	 * @param tekPoints the new current tek points
	 */
	public void setCurrentTekPoints( int tekPoints )
	{
		this.setCurrentTekPoints( new Long(tekPoints) );
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode()
	{
		final int prime = 31;
		int result = 1;
		result = prime
				* result
				+ ( ( currentTekPoints == null ) ? 0 : currentTekPoints
						.hashCode() );
		result = prime * result
				+ ( ( totalTekPoints == null ) ? 0 : totalTekPoints.hashCode() );
		return result;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj)
	{
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		TekPoints other = (TekPoints) obj;
		if (currentTekPoints == null)
		{
			if (other.currentTekPoints != null)
				return false;
		} else if (!currentTekPoints.equals( other.currentTekPoints ))
			return false;
		if (totalTekPoints == null)
		{
			if (other.totalTekPoints != null)
				return false;
		} else if (!totalTekPoints.equals( other.totalTekPoints ))
			return false;
		return true;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString()
	{
		return "TekPoints [totalTekPoints=" + this.totalTekPoints
				+ ", currentTekPoints=" + this.currentTekPoints + "]";
	}
}
